package day06;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.FileSystems;

public class Demo10 {
    public static void main(String[] args) {
        /*
         * 文件复制
         */
        File file1 = new File("F:", "kafka_2.13-2.4.1.tgz");
        File file2 = new File("F:", "demo.tgz");
        try {
            copy(file1, file2);
            System.out.println("复制成功");
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("复制失败");
        }
    }
    public static void copy(File source, File target)
        throws Exception{
        FileInputStream in = new FileInputStream(source);
        FileOutputStream out = new FileOutputStream(target);
        byte[] buf = new byte[8*1024];
        int n;
        while ((n = in.read(buf)) != -1){
            out.write(buf, 0, n);
        }
        in.close();
        out.close();
    }
}
